using IrisGenerator.Common.Modules;
using IrisGenerator.Common.Tools;
namespace IrisGenerator.Common.Core.Projects {
    
    
    public partial class Project {
        
        private System.Nullable<System.Guid> _proId;
        
        private string _proName;
        
        private System.Nullable<System.DateTime> _proCreation;
        
        private System.Nullable<System.DateTime> _proModification;
        
        private System.Nullable<System.DateTime> _proAnalyze;
        
        private System.Nullable<System.DateTime> _proGenerate;
        
        private ModuleInstanceCollection _moduleInstanceCollection;
        
        public virtual System.Nullable<System.Guid> ProId {
            get {
                return _proId;
            }
            set {
                _proId = value;
            }
        }
        
        public virtual string ProName {
            get {
                return _proName;
            }
            set {
                _proName = value;
            }
        }
        
        public virtual System.Nullable<System.DateTime> ProCreation {
            get {
                return _proCreation;
            }
            set {
                _proCreation = value;
            }
        }
        
        public virtual System.Nullable<System.DateTime> ProModification {
            get {
                return _proModification;
            }
            set {
                _proModification = value;
            }
        }
        
        public virtual System.Nullable<System.DateTime> ProAnalyze {
            get {
                return _proAnalyze;
            }
            set {
                _proAnalyze = value;
            }
        }
        
        public virtual System.Nullable<System.DateTime> ProGenerate {
            get {
                return _proGenerate;
            }
            set {
                _proGenerate = value;
            }
        }
        
        public virtual ModuleInstanceCollection ModuleInstanceCollection {
            get {
                if ((this._moduleInstanceCollection == null)) {
                    _moduleInstanceCollection = ModuleInstance.Select_MODULE_INSTANCE_By_PRO_ID(this.ProId);
                }
                return this._moduleInstanceCollection;
            }
        }
        
        private void Clean() {
            this.ProId = null;
            this.ProName = string.Empty;
            this.ProCreation = null;
            this.ProModification = null;
            this.ProAnalyze = null;
            this.ProGenerate = null;
            this._moduleInstanceCollection = null;
        }
        
        private void Fill(System.Data.DataRow dr) {
            this.Clean();
            if ((dr["PRO_ID"] != System.DBNull.Value)) {
                this.ProId = ((System.Nullable<System.Guid>)(dr["PRO_ID"]));
            }
            if ((dr["PRO_NAME"] != System.DBNull.Value)) {
                this.ProName = ((string)(dr["PRO_NAME"]));
            }
            if ((dr["PRO_CREATION"] != System.DBNull.Value)) {
                this.ProCreation = ((System.Nullable<System.DateTime>)(dr["PRO_CREATION"]));
            }
            if ((dr["PRO_MODIFICATION"] != System.DBNull.Value)) {
                this.ProModification = ((System.Nullable<System.DateTime>)(dr["PRO_MODIFICATION"]));
            }
            if ((dr["PRO_ANALYZE"] != System.DBNull.Value)) {
                this.ProAnalyze = ((System.Nullable<System.DateTime>)(dr["PRO_ANALYZE"]));
            }
            if ((dr["PRO_GENERATE"] != System.DBNull.Value)) {
                this.ProGenerate = ((System.Nullable<System.DateTime>)(dr["PRO_GENERATE"]));
            }
        }
        
        public static ProjectCollection GetAll() {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                System.Data.DataSet ds = dbo.PROJECT_Select_All();
                ProjectCollection collection = new ProjectCollection();
                if (GlobalTools.IsSafeDataSet(ds)) {
                    for (int i = 0; (i < ds.Tables[0].Rows.Count); i = (i + 1)) {
                        Project obj = new Project();
                        obj.Fill(ds.Tables[0].Rows[i]);
                        if ((obj != null)) {
                            collection.Add(obj);
                        }
                    }
                }
                return collection;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public static Project Load(System.Nullable<System.Guid> PRO_ID) {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                System.Data.DataSet ds = dbo.PROJECT_Select_One(PRO_ID);
                Project obj = null;
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        obj = new Project();
                        obj.Fill(ds.Tables[0].Rows[0]);
                    }
                }
                return obj;
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Load() {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                System.Data.DataSet ds = dbo.PROJECT_Select_One(this.ProId);
                if (GlobalTools.IsSafeDataSet(ds)) {
                    if ((ds.Tables[0].Rows.Count > 0)) {
                        this.Fill(ds.Tables[0].Rows[0]);
                    }
                }
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Insert() {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                dbo.PROJECT_Insert(this.ProName, this.ProCreation, this.ProModification, this.ProAnalyze, this.ProGenerate);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Delete() {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                dbo.PROJECT_Delete(this.ProId);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
        
        public virtual void Update() {
            IrisGenerator.Dal.Project dbo = null;
            try {
                dbo = new IrisGenerator.Dal.Project();
                dbo.PROJECT_Update(this.ProId, this.ProName, this.ProCreation, this.ProModification, this.ProAnalyze, this.ProGenerate);
            }
            catch (System.Exception ) {
                throw;
            }
            finally {
                if ((dbo != null)) {
                    dbo.Dispose();
                }
            }
        }
    }
}
